import Vue from 'vue'
import Vuex from 'vuex'
import { request, uploadRequest } from '@/plugins/request'
import api from '@/service/api'

Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
        hasLogin: false,
        userInfo: {},
		journeyId:'',
		routeType:'',
		token:'',
		journeyMessage:'',
		nationIndex:0,
		idIndex:0,
		journeyType: '',
        patientId: null,
		permission:[],
		userId: '',
		tableId: '',
		isRetinue: 0,
		isAdmin: false,
		msgTimer: null,
		workorderbtnPermission:{}
    },
    mutations: {
        login(state, provider) {
            // console.log('==========================index into ');
            // console.log(provider)
            state.hasLogin = true;
            state.userInfo = provider;
			state.userId = provider.account.id;
			let isAdmin = false
			if(provider!=null && provider.account!=null && provider.account.type == 1) {
				isAdmin = true
			}
			state.isAdmin = isAdmin // 判断是否管理员账号
            uni.setStorage({//缓存用户登陆状态
                key: 'userInfo',
                data: provider
            })
            uni.setStorageSync('token', provider.token) //缓存token
        },
        logout(state) {
            state.hasLogin = false;
			clearInterval(state.msgTimer)
			state.msgTimer = null
            state.userInfo = {};
            uni.removeStorage({
                key: 'userInfo'
            })
        }
    },
    actions: {

    }
})

export default store
